package com.example.controller.redismybatis;

import com.example.component.common.RedisUtil;
import com.example.pojo.entity.redismybatis.User;
import com.example.mapper.redismybatis.UserRedisMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2020/9/26 15:17
 */
@RestController
public class UserController {

    @Autowired
    private UserRedisMapper userMapper;


    @Autowired
    private RedisUtil redisUtil;

    @RequestMapping("/getUsers")
    public List<User> getUsers() {
        List<User> users=userMapper.getAll();
        redisUtil.lSet("users",users.get(1).toString());
        return users;
    }

    @RequestMapping("/getUser")
    public User getUser(Long id) {
        User user=userMapper.getOne(id);
        return user;
    }

    @RequestMapping("/add")
    public void save(User user) {
        userMapper.insert(user);
    }

    @RequestMapping(value="update")
    public void update(User user) {
        userMapper.update(user);
    }

    @RequestMapping(value="/delete/{id}")
    public void delete(@PathVariable("id") Long id) {
        userMapper.delete(id);
    }

}
